package com.morningstar.qs.basic.db.dto;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.morningstar.qs.basic.db.bean.LableItem;

public class LableItemDto extends LableItem {

	/**
	 * 
	 */
	private static final long serialVersionUID = -260575803238947070L;
	/**
	 * keys are language type
	 */
	private Map<String, TargetLangDto> targetLanguages;
	private Set<Integer> components;
    private String decodeTargetLangValue;
	public void addTargetLangDto(TargetLangDto tld) {
		if (targetLanguages == null)
			targetLanguages = new HashMap<String, TargetLangDto>();
		targetLanguages.put(tld.getLangType(), tld);
	}

	public void addComponent(Integer compId) {
		if (components == null)
			components = new HashSet<Integer>();
		components.add(compId);
	}

	public TargetLangDto getLang(String lang) {
		if (targetLanguages != null) {
			return targetLanguages.get(lang);
		}
		return null;
	}

	public TargetLangDto getLang(Integer compId, String lang) {
		if (!components.contains(compId))
			return null;
		if (targetLanguages != null)
			targetLanguages.get(lang);
		return null;
	}

	@Override
	public boolean equals(Object arg0) {
		return getLable().equals((((LableItemDto)arg0).getLable()));
	}

	@Override
	public int hashCode() {
		return getLable().hashCode();
	}

	public TargetLangDto findByLangType(String langType) {
		if(targetLanguages!=null) return targetLanguages.get(langType);
		return null;
	}

	public String getDecodeTargetLangValue() {
		return this.decodeTargetLangValue;
	}

	public void setDecodeTargetLangValue(String decodeTargetLangValue) {
		this.decodeTargetLangValue = decodeTargetLangValue;
	}
	
	public String toString() {
		StringBuilder sb=new StringBuilder();
		//sb.append("Language: "+targetLanguages!=null? targetLanguages.keySet().toString():"");
		sb.append("Language: "+((targetLanguages!=null && targetLanguages.keySet()!=null)? targetLanguages.keySet().toString():""));
		sb.append(" \t").append("Components: ").append(components!=null? components.toString(): "");
		return sb.toString();
	}

	@Override
	public String getLable() {
		return super.getLable().toLowerCase();
	}
	
	
}
